﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using MindBreaker.GameObjects;

namespace MindBreaker
{
    public class ObjectManager : DrawableGameComponent
    {
        /**************************/
        /** SINGLETON ObjectManager **/
        /**************************/
        private static ObjectManager instance;

        private ObjectManager(Game game) : base(game)
        {
            Console.WriteLine("Création de l'Object Manager");
            this._game = game;
            this.objectList = new List<GameObject>();
            this.Game.Components.Add(this);
        }

        public static ObjectManager getInstance(Game game)
        {
            if (instance == null)
                instance = new ObjectManager(game);
            return instance;
        }

        /****************/
        /** ATTRIBUTES **/
        /****************/

        private Game _game;
        private List<GameObject> objectList;


        //Ajout d'un objet à la liste d'objets
        public void addObject(GameObject objGame)
        {
            this.ObjectList.Add(objGame);
        }

        //Gestion des collisions entre les objets du Game
        public void collisionManager(GameObject obj1, GameObject obj2)
        {
            if (obj1.Bbox.Intersects(obj2.Bbox))
            {
                    Console.WriteLine("Collision entre " + obj1.ToString() + " et " + obj2.ToString());
                    obj2.PosX = 570;
            }
        }

        public override void Update(GameTime gameTime)
        {
            this.collisionManager(ObjectList[0], ObjectList[1]);
            base.Update(gameTime);
        }

        public List<GameObject> ObjectList
        {
            get { return objectList; }
            set { objectList = value; }
        }



    }
}
